import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/login/";
import Home from "@/views/home";
import homeLayout from "@/views/homeLayout/";
import Article from "@/views/article/";
import Publish from "@/views/publish/";
import Image from "@/views/image/";
import Comment from "@/views/comment/";
import Setting from "@/views/setting/";
import Fans from "@/views/fans/";

Vue.use(VueRouter);

const routes = [
  {
    //重定向
    path: "",
    redirect: "/login"
  },
  {
    path: "/login",
    name: "login",
    component: Login
  },
  {
    path: "/",
    component: homeLayout,
    children: [
      {
        path: "/home", //path 为空 ,会默认作为子路由渲染
        name: "home",
        component: Home
      },
      {
        path: "/article",
        name: "article",
        component: Article
      },
      {
        path: "/publish",
        component: Publish
      },
      {
        path: "/image",
        component: Image
      },
      {
        path: "/comment",
        component: Comment
      },
      {
        path: "/setting",
        component:Setting
      },
      {
        path: "/fans",
        component:Fans
      }
    ]
  }
];

const router = new VueRouter({
  routes
});

// //路由权限      路由导航守卫
// router.beforeEach((to, from, next) => {
//   const user =  JSON.parse( window.localStorage.getItem('user'))
//   //如果 要访问的页面不是 /login  校验登录状态
//   //如果没有登录，则跳转到登陆状态
//   //登陆了，就允许通过
//   if (to.path != '/login') {
//     if (user) {//判断是否是登陆状态      如果是登陆状态就会有本地存储
//       next()
//     } else {
//       next({path:'/login'}) //没有本地存储跳到 登陆页
//     }
//   } else {
//     next()
//   }
//   next()
// })
export default router;
